package adminServlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import userDao.UserDao;
import userEntity.User;
import userImplment.UserImplement;

/**
 * Servlet implementation class AdminResetUser
 */
public class AdminResetUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AdminResetUser() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int id=Integer.parseInt(request.getParameter("id"));
		String Uname = request.getParameter("Uname");
		String passWord = request.getParameter("passWord");
		String idType = request.getParameter("idType");
		String idCard = request.getParameter("idCard");
		String phone = request.getParameter("phone");
		int balance=Integer.parseInt(request.getParameter("balance"));

		System.out.println(balance);

		UserDao userImplement=new UserImplement();	
		HttpSession session=request.getSession();
	//将表单获得的用户信息封装为一个User对象
		User user=userImplement.Query(id);
		user.setUname(Uname);
		user.setPassWord(passWord);
		user.setIdType(idType);
		user.setIdCard(idCard);
		user.setPhone(phone);
		user.setBalance(balance);
			if(userImplement.Reset(user, id)) {
				session.setAttribute("userList", userImplement.GetAllUser());
				request.getRequestDispatcher("adminUser.jsp").forward(request, response);
			}else {
				//插入失败跳转到出错提示页面
				System.out.print("修改用户失败");
			}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
